#include "gameObjects.h"

/**********************************************************
 **********************************************************
 **********************************************************
 **                        SHIP                          **
 **********************************************************
 **********************************************************
 **********************************************************/



/**********************************************************
 * Ship Constructor : Ship Functions start here
 **********************************************************/
Ship::Ship() : Shootable()
{
   setX(0);
   setY(0);
   m_shipAngle = -90;
   m_isAlive   = true;
   m_lives     = MAX_LIVES;
}

/**********************************************************
 * event : handles input for ship
 **********************************************************/
void Ship::event(int up, int left, int right)
{
   if (isAlive())
   {
      m_shipAngle = m_shipAngle +
                    (left)
                    -
                    (right);

      static int flicker = 0;
      if (up)
      {
         if (flicker++ % 2 == 0)
            drawCoolFire(getPoint(), (int)getAngle());
         // angle the ship should go
         setAngle(m_shipAngle);
         setSpeed(0.2);
         *this += *this;
      }
   }
}

/**********************************************************
 * Draws ship
 **********************************************************/
void Ship::draw()
{
   draw3dShip(getPoint(), m_shipAngle);
}

/**********************************************************
 * Reset Ship : sets the ship to the starting position
 **********************************************************/
void Ship::resetShip()
{
   setX(0);
   setY(0);
   setDx(0);
   setDy(0);
   m_shipAngle = -90;
}



/**********************************************************
 **********************************************************
 **********************************************************
 **                      BULLET                          **
 **********************************************************
 **********************************************************
 **********************************************************/



/**********************************************************
 * Bullet Constructor
 **********************************************************/
Bullet::Bullet()
{
   // set the starting position of the bullets off the screen
   setX (250);
   setY (250);
   setDx(0);
   setDy(0);

   m_fWrap   = false;
   m_isFired = false;
   m_framesToLive = MAX_FRAMES;
}

/**********************************************************
 * Draw : draws bullet
 **********************************************************/
void Bullet::draw()
{
   drawDot(getPoint());
}



/**********************************************************
 **********************************************************
 **********************************************************
 **                        ROCK                          **
 **********************************************************
 **********************************************************
 **********************************************************/



/**********************************************************
 * Draw : draws rock
 **********************************************************/
void Rock::draw()
{
   drawCircle(getPoint(), m_radius, m_points, m_rotation);
}

/**********************************************************
 * Operator ++ : moves the rock
 **********************************************************/
void Rock::operator ++ (int)
{
   wrap();
   addX(getDx());
   addY(getDy());
   m_rotation++;
}

/**********************************************************
 * Big Rock Constructor
 **********************************************************/
BigRock::BigRock() : Rock()
{
   m_size     = BIG;
   m_points   = 6;
   m_rotation = 0;
   m_radius   = 20;

   setX(random(-200, 200));
   setY(random(-200, 200));

   (getX() > 0) ? setDx(1 -  rand() % 4)
                : setDx(1 + -rand() % 4);
   (getY() > 0) ? setDy(1 -  rand() % 4)
                : setDy(1 + -rand() % 4);
}

/**********************************************************
 * Medium Rock Constructor
 **********************************************************/
MediumRock::MediumRock(list <Rock *>::iterator &r, int direction, float speed) : Rock()
{
   m_size     = MEDIUM;
   m_points   = 4;
   m_rotation = 0;
   m_radius   = 16;
   setDx((direction == LEFT )  ? -(*r)->getDx() - speed :  (*r)->getDx() + speed);
   setDy((direction == LEFT)  ?   (*r)->getDy() + speed : -(*r)->getDy() - speed);
   setX((*r)->getX());
   setY((*r)->getY());
}

/**********************************************************
 * Small Rock Constructor
 **********************************************************/
SmallRock::SmallRock(list <Rock *>::iterator &r, int direction, float speed) : Rock()
{
   m_size     = SMALL;
   m_points   = 3;
   m_rotation = 0;
   m_radius   = 13;
   setDx((direction == UP  )  ? -(*r)->getDx() + speed :  (*r)->getDx() + speed);
   setDy((direction == DOWN)  ?  (*r)->getDy() + speed : -(*r)->getDy() - speed);
   setX((*r)->getX());
   setY((*r)->getY());
}



/**********************************************************
 **********************************************************
 **********************************************************
 **                       SCORE                          **
 **********************************************************
 **********************************************************
 **********************************************************/



/**********************************************************
 * Score Constructor
 **********************************************************/
Score::Score()
{
   m_scoreLocation.setX(-198);
   m_scoreLocation.setY( 198);
   m_score = 0;
}

/**********************************************************
 * Draw Score : draws the score
 **********************************************************/
void Score::drawScore()
{
   drawNumber(m_scoreLocation, m_score);
}

